Skip to content

add date support, with explicit now - #469

Closed
dferber90 wants to merge 4 commits into
mainfrom
now
Closed

add date support, with explicit now#469
dferber90 wants to merge 4 commits into
mainfrom
now

Conversation

@dferber90

@dferber90 dferber90 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

This PR adds explicit time support to flag evaluation. It adds a now value. The now value is the current time in epoch milliseconds.

Why we need this

Some flags use time-based conditions. Some flags use time-based rollouts. Before this PR, the code read the time with Date.now() at each check. Different flags in the same request could read different times. This PR fixes that problem.

How it works

  • Each request locks one now value at the start.
  • All flags in the same request use this same now value.
  • All flags in the same batch use this same now value.
  • The system passes now through decide() and bulkDecide().
  • The system passes now through evaluate() and bulkEvaluate().
  • Adapters receive now as a parameter. Adapters do not need to call Date.now() themselves.

New condition type

  • This PR adds a now accessor for conditions.
  • Rule authors can compare the current time against a fixed timestamp.
  • The comparison uses the existing operators: greater-than, greater-than-or-equal, less-than, less-than-or-equal.

Changed files

  • packages/flags/src/types.ts: Adds now to the Decide and Adapter types.
  • packages/flags/src/next/evaluate.ts: Locks now once per batch. Passes now to each flag.
  • packages/flags/src/sveltekit/index.ts: Locks now once per request context. Passes now to each flag.
  • packages/adapter-vercel/src/index.ts: Passes now to evaluate() and bulkEvaluate().
  • packages/vercel-flags-core/src/types.ts: Adds the now field to EvaluationParams. Adds the NOW accessor type.
  • packages/vercel-flags-core/src/evaluate.ts: Reads now from EvaluationParams instead of calling Date.now(). Uses now for rollout timing and for the new now accessor.
  • packages/vercel-flags-core/src/controller-fns.ts and create-raw-client.ts: Add an options parameter with now. Default to the evaluation start time when the caller does not pass now.
  • Test files: Update existing tests to pass a fixed now value.

Backward compatibility

  • The now option is optional at the client API level.
  • When a caller does not pass now, the code falls back to the evaluation start time.

@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flags-playground Ready Ready Preview Aug 12, 2026 11:16am
flags-sdk-dev Ready Ready Preview Aug 12, 2026 11:16am
flags-sdk-snippets Ready Ready Preview Aug 12, 2026 11:16am
flags-sdk-sveltekit-snippets Ready Ready Preview Aug 12, 2026 11:16am
shirt-shop Ready Ready Preview Aug 12, 2026 11:16am
shirt-shop-api Ready Ready Preview Aug 12, 2026 11:16am

dferber90 and others added 3 commits August 12, 2026 11:39
Extend BEFORE/AFTER to accept epoch ms and ISO strings so the now accessor works, and add evaluation coverage for locked time.
Share one evaluation timestamp across standalone flag() and evaluate()
calls keyed by the same request identity as identify caching.
@dferber90

Copy link
Copy Markdown
Collaborator Author

Change of plans.

An app can do const now = dedupe(() => Date.now()) to produce a consistent timestamp for the duration of a request. This can then be provided as an evaluation context input that will not bust any caches.

We're adding general support for timestamp based dates to the Vercel Flags UI, so the current date works just like updatedAt, createdAt timestamps etc.

@dferber90 dferber90 closed this Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants